unit cheque;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, DBCtrls,
  ExtCtrls, StdCtrls, Mask, ToolEdit, RXDBCtrl, Buttons;

type
  TfrmCheque = class(TForm)
    Label1: TLabel;
    edtFechaEmi: TDBDateEdit;
    Label2: TLabel;
    edtFechaCob: TDBDateEdit;
    Label5: TLabel;
    cmbBanco: TDBLookupComboBox;
    edtImporte: TDBEdit;
    Label4: TLabel;
    edtNum: TDBEdit;
    Label6: TLabel;
    edtCUIT: TDBEdit;
    Label3: TLabel;
    sCheque: TDataSource;
    cdsBanco: TSQLClientDataSet;
    cdsCheque: TSQLClientDataSet;
    cdsChequeID_CHEQUE: TIntegerField;
    cdsChequeID_BANCO: TSmallintField;
    cdsChequeFECHA_EMISION: TSQLTimeStampField;
    cdsChequeFECHA_COBRO: TSQLTimeStampField;
    cdsChequeCUIT: TStringField;
    cdsChequeIMPORTE: TFloatField;
    cdsChequebanco: TStringField;
    cdsChequeNUMERO: TStringField;
    SpeedButton1: TSpeedButton;
    btnGrabar: TSpeedButton;
    nv: TDBNavigator;
    cdsBancoID_BANCO: TSmallintField;
    cdsBancoBANCO: TStringField;
    procedure cdsChequeNewRecord(DataSet: TDataSet);
    procedure SpeedButton1Click(Sender: TObject);
    procedure btnGrabarClick(Sender: TObject);
    procedure sChequeStateChange(Sender: TObject);
  private
    Fusuario: word;
    FidCheque: integer;
    procedure Setusuario(const Value: word);
    procedure SetidCheque(const Value: integer);

  published
    property usuario: word read Fusuario write Setusuario;
    property idCheque: integer read FidCheque write SetidCheque;
  public
    constructor AltaModifCheque(AOwner: TComponent; usuario: word; idCh: integer);
  end;

var
  frmCheque: TfrmCheque;

implementation

uses MDatos, Recursos, banco, movCheque;

{$R *.dfm}

{ TfrmCheque }

constructor TfrmCheque.AltaModifCheque(AOwner: TComponent; usuario: word; idCh: integer);
begin
  inherited Create(Aowner);
  self.usuario := usuario;
  self.idCheque := idCh;
  self.cdsCheque.Params [0].AsInteger := self.idCheque;
  self.cdsCheque.Open;
  self.ShowModal;
end;

procedure TfrmCheque.Setusuario(const Value: word);
begin
  Fusuario := Value;
end;

procedure TfrmCheque.cdsChequeNewRecord(DataSet: TDataSet);
begin
  self.cdsChequeID_CHEQUE.AsInteger :=  id('CHEQUE_GEN');
  if self.cdsChequeID_CHEQUE.AsInteger = 0 then
    self.cdsCheque.Cancel;
end;

procedure TfrmCheque.SpeedButton1Click(Sender: TObject);
begin
  TfrmBanco.AltaModifBanco(self, self.usuario, self.cdsChequeID_BANCO.AsInteger);
  self.cdsBanco.Refresh;
end;

procedure TfrmCheque.btnGrabarClick(Sender: TObject);
begin
  self.cdsCheque.ApplyUpdates(0);
  TfrmMovCheque(self.Owner).idCheque := self.cdsChequeID_CHEQUE.AsInteger;
  self.Close;
end;

procedure TfrmCheque.sChequeStateChange(Sender: TObject);
begin
  self.btnGrabar.Enabled := self.cdsCheque.ChangeCount > 0;
end;

procedure TfrmCheque.SetidCheque(const Value: integer);
begin
  FidCheque := Value;
end;

end.
